﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for Performance
/// </summary>
public class PerformanceDAL
{
    static string connStr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
    static SqlConnection con = new SqlConnection(connStr);
    static SqlCommand cmd;
    static SqlDataAdapter da;
    static DataTable dt;

    public PerformanceDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static DataTable GetUserName(object userId)
    {
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "sp_GetSetUser";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@userId", userId);
        cmd.Parameters.AddWithValue("@TransType", 1);
        da = new SqlDataAdapter(cmd);
        dt = new DataTable();
        da.Fill(dt);
        return dt;
    }

    public static DataTable GetUserBasedOnRole(string role)
    {
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SP_GetAllUserByRole";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Role", role);
        //cmd.Parameters.AddWithValue("@Group", groupId);
        //cmd.Parameters.AddWithValue("@TransType", 1);
        da = new SqlDataAdapter(cmd);
        dt = new DataTable();
        da.Fill(dt);
        return dt;
    }


    public static DataTable GetGroup()
    {
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "sp_GetGroup";
        cmd.CommandType = CommandType.StoredProcedure;
        da = new SqlDataAdapter(cmd);
        dt = new DataTable();
        if (con.State == ConnectionState.Open)
            con.Close();
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            da.Fill(dt);
        }
        catch (Exception ex)
        {

        }

        finally
        {
            con.Close();
        }

        return dt;
    }

    public static DataTable GetChartInformation(object userId)
    {
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SP_GetStudentPerformanceRecord";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@UserId", userId);
        cmd.Parameters.AddWithValue("@TransType", 3);
        da = new SqlDataAdapter(cmd);
        dt = new DataTable();
        da.Fill(dt);
        return dt;
    }


}